package src.model.gameWorld.pathfinding.movement;

/**
 * <b>Overview</b>
 * DoubleMovementCost represents movement cost as a double-precision value.
 *
 * <b>Responsibilities</b>
 * Represent movement cost as a double-precision value and support double arithmetic.
 *
 * <b>Collaborators</b>
 * None.
 *
 * <b>Implementor</b> - Bruce
 * <b>Tester</b> - Tim
 *
 * @author Bruce
 */
public final class DoubleMovementCost implements MovementCost
{
	/**
	 * The value representing this Movement cost.
	 */
	double cost;

	/**
	 * Creates a new DoubleMovementCost.
	 *
	 * @param cost the double value that represents this movement cost.
	 * @throws IllegalArgumentException if the specified cost is negative.
	 */
	public DoubleMovementCost(double cost) throws IllegalArgumentException
	{
		if(cost < 0.0)
			throw new IllegalArgumentException();
		this.cost = cost;
	}

	/* (non-Javadoc)
	 * @see map.pathfinding.movement.MovementCost#add(map.pathfinding.movement.MovementCost)
	 */
	public void add(MovementCost other)
	{
		cost += other.getDoubleValue();
	}

	/* (non-Javadoc)
	 * @see map.pathfinding.movement.MovementCost#getDoubleValue()
	 */
	public double getDoubleValue()
	{
		return cost;
	}

	/* (non-Javadoc)
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	public int compareTo(MovementCost other)
	{
		return (int)(getDoubleValue() - other.getDoubleValue());
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#clone()
	 */
	@Override
	public DoubleMovementCost clone()
	{
		return new DoubleMovementCost(getDoubleValue());
	}
}